#ifndef DATASTREAM_H_INCLUDED
#define DATASTREAM_H_INCLUDED

#include "types.h"

typedef enum { Input, Output } iomode;

class DataStream
{
    public:
        DataStream(const string& filename, iomode mode);
        virtual ~DataStream();

        static DataStream* create(ClassId* classId, const string& name, iomode mode);
        static void destroy(DataStream* ds);

        template <class T> bool operator >> (T& value) { return read(&value, sizeof(T)); }

        virtual bool read(void* data, size_t size) = 0;
        virtual int getReadOffset() = 0;
        virtual bool setReadOffset(int offset, ios_base::seekdir origin) = 0;

        template <class T> bool operator << (const T& value) { return write(&value, sizeof(T)); }

        virtual bool write(const void* data, size_t size) = 0;
        virtual int getWriteOffset() = 0;
        virtual bool setWriteOffset(int offset, ios_base::seekdir origin) = 0;

    private:
        string mFileName;
        iomode mMode;
};

#include "filestream.h"

#endif // DATASTREAM_H_INCLUDED
